package com.rustic.server.dto.user;

import cn.hutool.core.bean.BeanUtil;
import cn.xy.commons.enums.DataStatus;
import cn.xy.commons.enums.YesNoStatus;
import cn.xy.commons.validator.EnumValidator;
import cn.xy.commons.validator.MobilePhone;
import com.rustic.server.enums.GenderEnum;
import com.rustic.server.po.User;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.Email;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotEmpty;


@Data
public class UpdatePersonalDTO {

    /**
     * 手机号码
     */
//    @MobilePhone(message = "请填写正确的手机号")
    @ApiModelProperty(value = "手机号码", dataType = "String")
    private String mobile;

    /**
     * 邮箱
     */
    @NotEmpty(message = "邮箱不能为空")
    @Email(message = "请填写正确的邮箱")
    @ApiModelProperty(value = "邮箱", dataType = "String")
    private String email;

    /**
     * 昵称
     */
    @NotEmpty(message = "昵称不能为空")
    @ApiModelProperty(value = "昵称", dataType = "String")
    private String nickname;

    /**
     * 头像
     */
    @Length(min = 0, max = 100, message = "头像地址长度为0-100个字符")
    @ApiModelProperty(value = "头像", dataType = "String")
    private String avatar;

    /**
     * 性别
     */
    @EnumValidator(clazz = GenderEnum.class, message = "请填写正确的性别")
    @ApiModelProperty(value = "性别(1男 2女 0未知)", dataType = "int")
    private int sex;

    /**
     * 年龄
     */
    @Min(value = 0, message = "年龄不能小于0")
    @ApiModelProperty(value = "年龄", dataType = "int")
    private int age;

    /**
     * 介绍
     */
    @Length(min = 0, max = 500, message = "介绍长度为0-500个字符")
    @ApiModelProperty(value = "介绍", dataType = "String")
    private String introduce;

    /**
     * 地区
     */
    @Length(min = 0, max = 500, message = "地区长度为0-500个字符")
    @ApiModelProperty(value = "地区", dataType = "String")
    private String address;

    public User toUser() {
        User user = new User();
        BeanUtil.copyProperties(this, user);
        user.setIsLock(YesNoStatus.NO.getValue());
        user.setDataStatus(DataStatus.NORMAL.getValue());
        return user;
    }
}
